package com.example.wanandroid_copy2.ui.search.dao

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.wanandroid_copy2.common.BaseApplication


@Database(entities = [Record::class],version = 1)
abstract class RecordDatabase : RoomDatabase(){

    abstract fun recordDao(): RecordDao

    companion object {
        @Volatile private var instance: RecordDatabase? = null
        private val LOCK = Any()

        operator fun invoke() = instance ?: synchronized(LOCK){
            instance ?: buildDatabase().also { instance = it}
        }

        private fun buildDatabase() = Room.databaseBuilder(BaseApplication.mContext,
            RecordDatabase::class.java,
            "wan_android_db")
            .allowMainThreadQueries()
            .build()
    }
}